/**
 * 
 */
package com.zho.common.consumer;

import java.util.Map;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * @author ho.viet.duan
 * 
 */
public class SpringConsumerResolver implements InitializingBean, DisposableBean {

    private Map<String, IConsumerController> consumers;

    /**
     * 
     */
    public void afterPropertiesSet() throws Exception {
        if (consumers != null) {
            for (String key : consumers.keySet()) {
                ConsumerManager.register(key, consumers.get(key));
            }
        }
        ConsumerManager.startAll();
    }

    /**
     * 
     */
    public void destroy() throws Exception {
        ConsumerManager.stopAll();
    }

    /**
     * @return the consumers
     */
    public Map<String, IConsumerController> getConsumers() {
        return consumers;
    }

    /**
     * @param consumers
     *            the consumers to set
     */
    public void setConsumers(Map<String, IConsumerController> consumers) {
        this.consumers = consumers;
    }

}
